{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 比较运算符\n",
    "- 对两个变量或者值进行比较的运算符\n",
    "- 比较的结果是布尔值，即True/False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "# == ，等号\n",
    "a = 3 ** 4\n",
    "b = a == 80\n",
    "print(b)\n",
    "# != 不等于\n",
    "# > 大于\n",
    "# < 小于\n",
    "# >= 大于等于\n",
    "# <= 小于等于"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 赋值运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11\n"
     ]
    }
   ],
   "source": [
    "# = ，赋值\n",
    "a = 0 \n",
    "c = a = 4\n",
    "\n",
    "# += ,缩写\n",
    "a += 7\n",
    "print(a)\n",
    "\n",
    "# 所有数学运算符都有缩写形式\n",
    "# .=， *= ，/=，//=，%=，**="
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 逻辑运算符\n",
    "- 对布尔值进行计算的符号\n",
    "- and 逻辑与\n",
    "- or 逻辑或\n",
    "- not 逻辑非\n",
    "- Python中逻辑运算没有异或运算\n",
    "- 运算规则：\n",
    "    - and看做乘法，or看做加法\n",
    "    - TRUE看做1，FALSE看做0\n",
    "    - 则逻辑运算符就能转换成证书数学运算\n",
    "    - 最后结果如果为0则为FALSE，否则为TRUE\n",
    "- 逻辑运算的短路问题\n",
    "    - 逻辑运算式，按照运算顺序计算，一旦能够确定整个式子未来的值，则不再进行计算，直接返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 逻辑运算符短路案例\n",
    "# 下面逻辑表达式，a的值一定为TRUE,则运行到or的时候，整个表达式不再向下运算\n",
    "i = 1\n",
    "a = True or xxxx\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 成员运算符号\n",
    "- 用来检测某一个变量是否是另外一个变量的成员\n",
    "- in \n",
    "- not in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "l = [1,2,3,4]\n",
    "print(7 in l)\n",
    "print(4 in l)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 身份运算\n",
    "- is: 用来检测两个变量是否是同一个变量\n",
    "    - 语法 var1 is var2\n",
    "- is not: 两个变量不是同一个变量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 运算符的优先级问题\n",
    "- 永远记住，括号具有最高先级"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
